
//print
$(".btn-print").click(function(){
	$(".nav-tabs").hide();
	window.print();
	$(".nav-tabs").show();
});
//按周 统计  
function callbackByWeek(target, retdata, datetime){
		//按周显示统计信息
		var data = retdata.data3;
		
		var sum =0;
		for (var index in data[0]) {
			sum += data[1][index];
		}
		if(sum==0){
			alert("暂无数据");
			return false;
		}
		target.find("div[name='sum']").html("<center>停车场总量：<font color=red> "+sum+" </font></center>");
		
		data[0]= ["周一","周二","周三","周四","周五","周六","周日"]; 
		var map2 = target.find("div[name='map2']");
		var map1 = target.find("div[name='map1']");
		map2.hide();
		map1.show();
		drawMapByMonth(map1, data, datetime+"所在周", "按周统计", "");
	
}
//按年 统计  
function callbackByYear(target, retdata, datetime){
	//按月显示统计信息
		var data = retdata.data1;
		var sum = 0;
		for (var index in data[0]) {
			data[0][index] = data[0][index] + "月";
			sum += data[1][index];
		}
		if(sum==0){
			alert("暂无数据");
			return false;
		}
		target.find("div[name='sum']").html("<center>停车场总量：<font color=red> "+sum+" </font></center>");
		var map2 = target.find("div[name='map2']");
		var map1 = target.find("div[name='map1']");
		map2.hide();
		map1.show();
		drawMapByMonth(map1, data, datetime+ "年   停车场统计", "", "月");
}

//按月 统计  
function callbackByMonth(target, retdata, datetime){
		//按天显示统计信息
		var data = retdata.data2;
		var sum = 0;
		for(var index in data[0]){
			data[0][index] = data[0][index] + "日";
			sum += data[1][index];
		}
		if(sum==0){
			alert("暂无数据");
			return false;
		}
		target.find("div[name='sum']").html("<center>停车场总量：<font color=red> "+sum+" </font></center>");
		var map2 = target.find("div[name='map2']");
		var map1 = target.find("div[name='map1']");
		map2.hide();
		map1.show();
		drawMapByMonth( map1, data, datetime+"月  停车场统计", "按月统计", "日");
		
}
//曲线图
function drawMapByMonth(obj, data, title, name, xformat){
	obj.highcharts({
		 	chart: {
	            type: 'area'
	        },
	        title: {
	            text: title
	        },
	        subtitle: {
	            text: name
	        },
	        xAxis: {
        	   title: {
	              text: '日期'
	           },
	           allowDecimals: false,
//	           categories: data[0],
	           labels: {
	                formatter: function() {
	                    return this.value + xformat ;
	                }
	            }
	        },
	        yAxis: {
	            title: {
	                text: '数量(个)'
	            },
	            labels: {
	                formatter: function() {
	                    return this.value +'个';
	                }
	            }
	        },
	        exporting: {
	            enabled: false
	        },
	        credits:{
	        	enabled: false,
	        	href: 'http://ipark.teleframe.cn',
	        	text: 'ipark.teleframe.cn',
	        },
	        tooltip: {
	            pointFormat: '{series.name}  {point.x}'+xformat+': <b>{point.y} 个  </b>'
	        },
	        plotOptions: {
	            area: {
	                pointStart: 1,
	                marker: {
	                    enabled: false,
	                    symbol: 'circle',
	                    radius: 2,
	                    states: {
	                        hover: {
	                            enabled: true
	                        }
	                    }
	                }
	            }
	        },
	        series: [{
		         name: '停车场数量',
	             data: data[1]
	        }]
    });
}

function DrawTable( target, retdata, datetime)
{
	var list = retdata.list;
	if(list.length==0){
		alert("暂无数据");
		return false;
	}
	var html = "";
	//
	var time = new Date();
	var tableId = "mytable_"+time.getTime();
	html +="<center><div class=\"print hidden\" id=\"print-title\"> <h2>停车场收入额统计</h2> </div></center>";
	html += "<br /> <div  >";
	html += "<table id=\""+tableId+"\" style=\"width:99%;min-width:400px;\" class=\"table table-hover\">";
	html += "<thead>";
		html += "<tr role=\"head\">";
		html += "  <th sort=\"true\">" +"停车场名称"+ "</th>";
		html += "  <th sort=\"true\">" +"预定总量(条)"+ "</th>";
		html += "  <th sort=\"true\">" +"成交总量(条)"+ "</th>";
		html += "  <th sort=\"true\">" +"应收总金额(元)"+ "</th>";
		html += "  <th sort=\"true\">" +"实收总金额(元)"+ "</th>";
		html += "</tr>";
		html += "</thead>";
	for(var i=0; i<list.length; i++){
		html += "<tr>";
		html += "  <td>" + list[i].parkname + "</td>";
		html += "  <td>" + list[i].ordersuncount + "</td>";
		html += "  <td>" + list[i].orderokcount + "</td>";
		html += "  <td>" + list[i].reAmount +"</td>";
		html += "  <td>" + list[i].acAmount + "</td>";
		html += "</tr>";
	}
	html += "</table>";
	html += "</div >";
	var map2 = target.find("div[name='map2']");
	var map1 = target.find("div[name='map1']");
	map2.html( html );
	map1.hide();
	map2.show();
	
	//排序
	$("#"+tableId).sorttable({
	    ascImgUrl: "scripts/jquery/tableSorter/images/bullet_arrow_up.png",
	    descImgUrl: "scripts/jquery/tableSorter/images/bullet_arrow_down.png",
	    ascImgSize: "8px",
	    descImgSize: "8px",
	    onSorted: function (cell) {
	    }
	});
	
}

$("div.container>div.row input[type='button']").click(function(){
	var stattype = $(this).attr("stattype");
	var stattypefor = $(this).attr("for");
	var callbackMap = $(this).attr("callback");
	var method =  $(this).attr("method");
	var target = $(this).parent().parent();
	var datetime = $("#"+stattypefor).val();
	if(window.console){
		console.log("stattype="+stattype+" stattypefor="+stattypefor);
	}
	var data={
			stattype: stattype,
			datetime: datetime
		};
	startMask();//等待提示开启
	$.ajax({
		type: 'POST',
		url: "ParkStatAction?method="+method+"&querytype=json",
		data: data,
		success: function(retdata){
			endMask();//等待提示关闭
			if(window.console){
				console.log(retdata);
			}
			
			if(retdata.error==-100){
				alert( retdata.msg );
				window.top.location = retdata.url;
			}else{
				if(retdata.error==0){
					window[callbackMap]( target, retdata, datetime );
				}else{
					alert( retdata.msg );
				}
			}
	  	},
	  	dataType: "json",
		error : function(XMLHttpRequest, textStatus, errorThrown){
			alert( XMLHttpRequest.responseText);
			endMask();//等待提示关闭
			$("#errorFiled").html( XMLHttpRequest.responseText );
			$("#errorFiled").show();
		}
	});
});
function switchtab( tabtype ){
	$("div.container>div.row").hide();
	$("div.container>div.row[type='"+tabtype+"']").show() ;
}

$("ul.nav-tabs li").mouseover(function(){
	var tab = $(this);
	var nav = tab.parent();
	$(nav).children("li").removeClass("active");
	tab.addClass("active");
	var type = $(this).attr("type");
	switchtab(type);
	return true;
});


